<!--
 * @Description: 未登录弹窗组件
 * @fileName: 
 * @Author: LiSuwan
 * @Date: 2023-09-23 14:11:39
 * @LastEditors: LiSuwan
 * @LastEditTime: 2023-09-23 14:42:39
-->
<template>
	<view>
		<!-- ====== 确认订单弹窗 start =======-->
		<vipPopup :title="'提示'" :tipsImg="'loginPopup'" :show="isShow" :btnTextLeft="'取消'" :btnTextRight="'登录'" :tips="'您还未登录，请先登录～'" @openVip="gotoLogin" @closePopup="closeDialog"></vipPopup>
		<!-- ====== 确认订单弹窗 end =======-->
	</view>
</template>

<script>
		import vipPopup from '@/components/vipPopup.vue'
export default {
	components:{
		vipPopup,
	},
	name: "unLogin",
	props:{
		isShow:{//是否显示弹窗
			type: Boolean,
			default: false
		},
	},
	watch:{
		isShow:{
			deep:true,//true为进行深度监听,false为不进行深度监听
			immediate:true, //立即执行
			handler(newVal){
				this.showDialog = newVal;
			}
		}
	},
	data() {
		return {			
			// ====== 静态图片路径 开始 ======
			statusImg: this.$staticImgurl + 'unlogin.png', //弹框状态图片
			// ====== 静态图片路径 结束 ======
			params:{
				code:"",//授权code
				anonymousCode:"",//匿名登录凭证
				type:"",//登录类型0.抖音1.百度


			}
		};
	},
	methods: {
        /**
         * @Description: 跳转到登录页面
         * @Author: LiSuwan
         * @Date: 2023-09-23 14:15:13
         */		
        gotoLogin() {
			let {uniPlatform}= this.$util.getDeviceInfo();//获取设备信息
			let that = this;
			if(uniPlatform == 'mp-toutiao'){
				
				tt.login({
				  force: true,
				  success(res) {
				    console.log(`login 调用成功${res.code} ${res.anonymousCode}`);
					that.params = {
						code:res.code,//授权code
						anonymousCode:res.anonymousCode,//匿名登录凭证
						type:0,//登录类型0.抖音1.百度
					}
					
					that.$api.post(that.$url.registerUser,that.params).then(res=>{
						if(res.code == 200){
							console.log(res.data)
							uni.setStorageSync("token",res.data.accessToken)
							uni.setStorageSync("userInfo",res.data)
							that.closeDialog();//关闭弹窗
						}else {
							that.$.msg(res.error || res.msg)
						}
					})
					
					
				  },
				  fail(res) {
				    console.log(`login 调用失败`);
				  },
				});
				
				
				
				
				
			}
			
			
			
			
			
            
        },
		/**
		 * @Description: 关闭弹窗
		 * @Author: LiSuwan
		 * @Date: 2023-09-23 14:17:18
		 */		
		closeDialog() {
			this.$emit('close'); //把 close 事件传给父组件
        },
		
	},
}
</script>

<style></style>